namespace WP7Contrib.Services.BingMaps.Model
{
    using System.Device.Location;
    using Microsoft.Phone.Controls.Maps;
    using Common;

    public class LocationData : BaseModel, ICloneable<LocationData>
    {
        private string name;
        private GeoCoordinate point;
        private LocationRect boundingBox;
        private Address address;
        private Confidence confidence;

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.name, value, () => this.Name);
            }
        }

        public GeoCoordinate Point
        {
            get
            {
                return this.point;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.point, value, () => this.Point);
            }
        }

        public LocationRect BoundingBox
        {
            get
            {
                return this.boundingBox;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.boundingBox, value, () => this.BoundingBox);
            }
        }

        public Address Address
        {
            get
            {
                return this.address;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.address, value, () => this.Address);
            }
        }

        public Confidence Confidence
        {
            get
            {
                return this.confidence;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.confidence, value, () => this.Confidence);
            }
        }

        public bool HasAddress
        {
            get
            {
                return this.address != null;
            }
        }

        public bool HasPoint
        {
            get
            {
                return this.point != null;
            }
        }

        public bool HasBoundingBox
        {
            get
            {
                return this.boundingBox != null;
            }
        }

        public LocationData ShallowClone()
        {
            var data = new LocationData
            {
                Name = this.name,
                Point = this.point,
                BoundingBox = this.boundingBox,
                Address = this.address,
                Confidence = this.confidence          
            };

            return data;
        }

        public LocationData DeepClone()
        {
            var data = new LocationData
            {
                Name = this.name,
                Confidence = this.confidence
            };

            if (this.HasAddress)
                data.Address = this.Address.DeepClone();

            if (this.HasPoint)
                data.Point = new GeoCoordinate(this.Point.Latitude, this.Point.Longitude);

            if (this.HasBoundingBox)
                data.BoundingBox = new LocationRect(this.boundingBox.North, this.boundingBox.West, this.boundingBox.South, this.boundingBox.East);

            return data;
        }
    }
}